/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.icanci.loopstack.damc.admin.web.api;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import cn.icanci.loopstack.damc.admin.biz.service.RegisterTableService;
import cn.icanci.loopstack.damc.spi.model.R;
import cn.icanci.loopstack.damc.spi.model.SocketMessage;
import cn.icanci.loopstack.damc.spi.model.UriConstant;
import cn.icanci.loopstack.damc.spi.model.pubsub.LoadScriptDTO;
import cn.icanci.loopstack.damc.spi.model.pubsub.RegisterDTO;
import cn.icanci.loopstack.damc.spi.model.refresh.RefreshCell;

/**
 * 注册请求 
 * 
 * @author icanci
 * @since 1.0 Created in 2025/05/16 15:01
 */
@RestController
public class RegisterApiController {

    @Resource
    private RegisterTableService registerService;

    /**
     * 注册行为[此路径必须不能修改]
     * 
     * @param register register
     * @return 返回注册的结果
     */
    @PostMapping(UriConstant.REGISTER)
    public R register(@RequestBody RegisterDTO register) {
        registerService.register(register);
        return R.builderOk().data("register", register).build();
    }

    /**
     * 获取数据行为[此路径必须不能修改]
     * 
     * @param loadScript loadScript
     * @return 返回配置数据
     */
    @PostMapping(UriConstant.LOAD_SCRIPT)
    public SocketMessage loadScript(@RequestBody LoadScriptDTO loadScript) {
        List<RefreshCell> cells = registerService.loadScript(loadScript);
        return SocketMessage.success(cells);
    }
}
